import time


def timer(func):
    def wrapper(*args, **kwargs):
        begin = time.time()
        fun = func(*args, **kwargs)
        end = time.time()
        print("Cost {}s.".format(end - begin))
        return fun

    return wrapper


@timer
def test_fun():
    time.sleep(2)
    print("Over.")


if __name__ == '__main__':
    test_fun()
